var pageNo=1;
var pageTotal=1;
$(function(){
    //塑胶单选按钮点击事件
    $(".myrdo:radio").css("cursor","pointer");
    $(".myrdo:radio").click(function(){
        myrdo($(this));
    });
    $(".radio-text").css("cursor","pointer");
    $(".radio-text").click(function(){
        // alert($(this).prev().val());
        $(".myrdo:radio").prop("checked",false);
        $(this).prev().prop("checked",true);
        myrdo($(this).prev());
    });

});
//塑胶单选按钮点击事件
function myrdo($this) {
    var type=$this.val();
    var name=$("#name").val();
    var typename="";
    var url="/official/productListajax?name=" + name + "&typeWebsite=" + type;
    $.post(url,function(result){
        if(result.officialWebsitesList.length!=0){
            var sttable = "";
            for (var i = 0; i < result.officialWebsitesList.length; i++) {
                if (result.officialWebsitesList[i].type==1){
                    typename="综合资讯";
                } else if(result.officialWebsitesList[i].type==2){
                    typename="塑胶官网";
                } else if(result.officialWebsitesList[i].type==3){
                    typename="名站";
                } else if(result.officialWebsitesList[i].type==4){
                    typename="推荐供应商";
                }
                sttable += "<tr>";
                sttable += "<td width='25px'>";
                sttable += "<label><input type=\"checkbox\" class=\"ace\" ><span class=\"lbl\"></span></label>";
                sttable += "</td>";
                sttable += "<td width='80px'>";
                sttable += result.officialWebsitesList[i].id;
                sttable += "</td>";
                sttable += "<td width='200px'><img src='";
                sttable += result.officialWebsitesList[i].images;
                sttable += "'/></td>";
                sttable += "<td width='100px'>";
                sttable += result.officialWebsitesList[i].name;
                sttable += "</td>";
                sttable += "<td width='150px'><a target=\"_blank\" href='";
                sttable += result.officialWebsitesList[i].href;
                sttable += "'>"+result.officialWebsitesList[i].href+"</a></td>";
                sttable += "<td width='100px'>";
                sttable +=typename;
                sttable += "</td>";
                sttable += "<td width='100px'>";
                sttable += result.officialWebsitesList[i].idValue;
                sttable += "</td>";
                sttable += "<td width='100px'>";
                sttable += result.officialWebsitesList[i].idValue2;
                sttable += "</td>";
                sttable += "<td width='100px'>";
                sttable += result.officialWebsitesList[i].idValue3;
                sttable += "</td>";
                sttable += "<td  class=\"td-manage\">";
                sttable += " <a title=\"编辑\" onclick=\"member_edit('编辑','member-add.html','4','','510')\" href=\"javascript:;\"  class=\"btn btn-xs btn-info\" ><i class=\"icon-edit bigger-120\"></i></a>";
                sttable += " <a title=\"删除\" href=\"javascript:;\"  onclick=\"member_del(this,'1')\" class=\"btn btn-xs btn-warning\" ><i class=\"icon-trash  bigger-120\"></i></a>";
                sttable += "</td>";
                sttable += "</tr>";
            }
            $("#sertbody").html(sttable);
            pageNo = result.pageNo;
            pageTotal = result.pageTotal;
            var sttable2 = "";
            if (pageNo != pageTotal) {
                sttable2 += "<tr><td colspan='10' class='text-center'>";
                sttable2 += " <a id='downye' href='javascript:void(0);' onclick='downye();' name='down' value='下一页' style='cursor: pointer;'>下一页</a>";
                sttable2 += " <a id='meiye' href='javascript:void(0);' onclick='meiye();' style='cursor: pointer;'>尾页</a>";
                sttable2 += "</td></tr>";
            }
            $("#sertfoot").html(sttable2);
        } else {
            alert("没有数据！");
        }
    },"json");
    jj();
};

//搜索按钮点击事件
    function subbut() {
        var name = $("#name").val();
        var type = $(".myrdo:checked").val();
        var typename="";
        var url = "/official/productListajax?name=" + name + "&typeWebsite=" + type;
        $.post(url, function (result) {
            if (result.officialWebsitesList.length != 0) {
                var sttable = "";
                for (var i = 0; i < result.officialWebsitesList.length; i++) {
                    if (result.officialWebsitesList[i].type==1){
                        typename="综合资讯";
                    } else if(result.officialWebsitesList[i].type==2){
                        typename="塑胶官网";
                    } else if(result.officialWebsitesList[i].type==3){
                        typename="名站";
                    } else if(result.officialWebsitesList[i].type==4){
                        typename="推荐供应商";
                    }
                    sttable += "<tr>";
                    sttable += "<td width='25px'>";
                    sttable += "<label><input type=\"checkbox\" class=\"ace\" ><span class=\"lbl\"></span></label>";
                    sttable += "</td>";
                    sttable += "<td width='80px'>";
                    sttable += result.officialWebsitesList[i].id;
                    sttable += "</td>";
                    sttable += "<td width='200px'><img src='";
                    sttable += result.officialWebsitesList[i].images;
                    sttable += "'/></td>";
                    sttable += "<td width='100px'>";
                    sttable += result.officialWebsitesList[i].name;
                    sttable += "</td>";
                    sttable += "<td width='150px'><a target=\"_blank\" href='";
                    sttable += result.officialWebsitesList[i].href;
                    sttable += "'>"+result.officialWebsitesList[i].href+"</a></td>";
                    sttable += "<td width='100px'>";
                    sttable += typename;
                    sttable += "</td>";
                    sttable += "<td width='100px'>";
                    sttable += result.officialWebsitesList[i].idValue;
                    sttable += "</td>";
                    sttable += "<td width='100px'>";
                    sttable += result.officialWebsitesList[i].idValue2;
                    sttable += "</td>";
                    sttable += "<td width='100px'>";
                    sttable += result.officialWebsitesList[i].idValue3;
                    sttable += "</td>";
                    sttable += "<td  class=\"td-manage\">";
                    sttable += " <a title=\"编辑\" onclick=\"member_edit('编辑','member-add.html','4','','510')\" href=\"javascript:;\"  class=\"btn btn-xs btn-info\" ><i class=\"icon-edit bigger-120\"></i></a>";
                    sttable += " <a title=\"删除\" href=\"javascript:;\"  onclick=\"member_del(this,'1')\" class=\"btn btn-xs btn-warning\" ><i class=\"icon-trash  bigger-120\"></i></a>";
                    sttable += "</td>";
                    sttable += "</tr>";
                }
                $("#sertbody").html(sttable);
                pageNo = result.pageNo;
                pageTotal = result.pageTotal;
                var sttable2 = "";
                if (pageNo != pageTotal) {
                    sttable2 += "<tr><td colspan='10' class='text-center'>";
                    sttable2 += " <a id='downye' href='javascript:void(0);' onclick='downye();' name='down' value='下一页' style='cursor: pointer;'>下一页</a>";
                    sttable2 += " <a id='meiye' href='javascript:void(0);' onclick='meiye();' style='cursor: pointer;'>尾页</a>";
                    sttable2 += "</td></tr>";
                }
                $("#sertfoot").html(sttable2);
            } else {
                alert("没有数据！");
            }
        }, "json");
        jj();
    };

//为动态添加的元素重新绑定事件
    function jj() {
        $("#suoye").on("click", "suoye();");
        $("#upye").on("click", "upye();");
        $("#downye").on("click", "downye();");
        $("#meiye").on("click", "meiye();");
    }

//首页点击事件
    function suoye() {
        var name = $("#name").val();
        var type = $(".myrdo:checked").val();
        var typename="";
        var url = "/official/productListajax?pageNo=1&name=" + name + "&typeWebsite=" + type;
        $.post(url, function (result) {
            if (result.officialWebsitesList.length != 0) {
                var sttable = "";
                for (var i = 0; i < result.officialWebsitesList.length; i++) {
                    if (result.officialWebsitesList[i].type==1){
                        typename="综合资讯";
                    } else if(result.officialWebsitesList[i].type==2){
                        typename="塑胶官网";
                    } else if(result.officialWebsitesList[i].type==3){
                        typename="名站";
                    } else if(result.officialWebsitesList[i].type==4){
                        typename="推荐供应商";
                    }
                    sttable += "<tr>";
                    sttable += "<td width='25px'>";
                    sttable += "<label><input type=\"checkbox\" class=\"ace\" ><span class=\"lbl\"></span></label>";
                    sttable += "</td>";
                    sttable += "<td width='80px'>";
                    sttable += result.officialWebsitesList[i].id;
                    sttable += "</td>";
                    sttable += "<td width='200px'><img src='";
                    sttable += result.officialWebsitesList[i].images;
                    sttable += "'/></td>";
                    sttable += "<td width='100px'>";
                    sttable += result.officialWebsitesList[i].name;
                    sttable += "</td>";
                    sttable += "<td width='150px'><a target=\"_blank\" href='";
                    sttable += result.officialWebsitesList[i].href;
                    sttable += "'>"+result.officialWebsitesList[i].href+"</a></td>";
                    sttable += "<td width='100px'>";
                    sttable +=typename;
                    sttable += "</td>";
                    sttable += "<td width='100px'>";
                    sttable += result.officialWebsitesList[i].idValue;
                    sttable += "</td>";
                    sttable += "<td width='100px'>";
                    sttable += result.officialWebsitesList[i].idValue2;
                    sttable += "</td>";
                    sttable += "<td width='100px'>";
                    sttable += result.officialWebsitesList[i].idValue3;
                    sttable += "</td>";
                    sttable += "<td class=\"td-manage\">";
                    sttable += "<a title=\"编辑\" onclick=\"member_edit('编辑','member-add.html','4','','510')\" href=\"javascript:;\"  class=\"btn btn-xs btn-info\" ><i class=\"icon-edit bigger-120\"></i></a>";
                    sttable += "<a title=\"删除\" href=\"javascript:;\"  onclick=\"member_del(this,'1')\" class=\"btn btn-xs btn-warning\" ><i class=\"icon-trash  bigger-120\"></i></a>";
                    sttable += "</td>";
                    sttable += "</tr>";
                }
                $("#sertbody").html(sttable);
                pageNo = result.pageNo;
                pageTotal = result.pageTotal;
                var sttable2 = "";
                sttable2 += "<tr><td colspan='10' class='text-center'>";
                sttable2 += " <a id='downye' href='javascript:void(0);' onclick='downye();' name='down' value='下一页' style='cursor: pointer;'>下一页</a>";
                sttable2 += " <a id='meiye' href='javascript:void(0);' onclick='meiye();' style='cursor: pointer;'>尾页</a>";
                sttable2 += "</td></tr>";
                $("#sertfoot").html(sttable2);
            } else {
                alert("没有数据！");
            }
        }, "json");
        jj();
    };

//上一页点击事件
    function upye() {
        var name = $("#name").val();
        var type = $(".myrdo:checked").val();
        var typename="";
        var url = "/official/productListajax?pageNo=" + (pageNo - 1) + "&name=" + name + "&typeWebsite=" + type;
        $.post(url, function (result) {
            if (result.officialWebsitesList.length != 0) {
                var sttable = "";
                for (var i = 0; i < result.officialWebsitesList.length; i++) {
                    if (result.officialWebsitesList[i].type==1){
                        typename="综合资讯";
                    } else if(result.officialWebsitesList[i].type==2){
                        typename="塑胶官网";
                    } else if(result.officialWebsitesList[i].type==3){
                        typename="名站";
                    } else if(result.officialWebsitesList[i].type==4){
                        typename="推荐供应商";
                    }
                    sttable += "<tr>";
                    sttable += "<td width='25px'>";
                    sttable += "<label><input type=\"checkbox\" class=\"ace\" ><span class=\"lbl\"></span></label>";
                    sttable += "</td>";
                    sttable += "<td width='80px'>";
                    sttable += result.officialWebsitesList[i].id;
                    sttable += "</td>";
                    sttable += "<td width='200px'><img src='";
                    sttable += result.officialWebsitesList[i].images;
                    sttable += "'/></td>";
                    sttable += "<td width='100px'>";
                    sttable += result.officialWebsitesList[i].name;
                    sttable += "</td>";
                    sttable += "<td width='150px'><a target=\"_blank\" href='";
                    sttable += result.officialWebsitesList[i].href;
                    sttable += "'>"+result.officialWebsitesList[i].href+"</a></td>";
                    sttable += "<td width='100px'>";
                    sttable += typename;
                    sttable += "</td>";
                    sttable += "<td width='100px'>";
                    sttable += result.officialWebsitesList[i].idValue;
                    sttable += "</td>";
                    sttable += "<td width='100px'>";
                    sttable += result.officialWebsitesList[i].idValue2;
                    sttable += "</td>";
                    sttable += "<td width='100px'>";
                    sttable += result.officialWebsitesList[i].idValue3;
                    sttable += "</td>";
                    sttable += "<td class=\"td-manage\">";
                    sttable += "<a title=\"编辑\" onclick=\"member_edit('编辑','member-add.html','4','','510')\" href=\"javascript:;\"  class=\"btn btn-xs btn-info\" ><i class=\"icon-edit bigger-120\"></i></a>";
                    sttable += "<a title=\"删除\" href=\"javascript:;\"  onclick=\"member_del(this,'1')\" class=\"btn btn-xs btn-warning\" ><i class=\"icon-trash  bigger-120\"></i></a>";
                    sttable += "</td>";
                    sttable += "</tr>";
                }
                $("#sertbody").html(sttable);
                var sttable2 = "";
                sttable2 += "<tr><td colspan='10' class='text-center'>";
                pageNo = result.pageNo;
                pageTotal = result.pageTotal;
                if (pageNo != 1) {
                    sttable2 += " <a id='suoye' href='javascript:void(0);' onclick='suoye();' style='cursor: pointer;'>首页</a>";
                    sttable2 += " <a id='upye' href='javascript:void(0);' onclick='upye();' style='cursor: pointer;'>上一页</a>";
                }
                sttable2 += " <a id='downye' href='javascript:void(0);' onclick='downye();' name='down' value='下一页' style='cursor: pointer;'>下一页</a>";
                sttable2 += " <a id='meiye' href='javascript:void(0);' onclick='meiye();' style='cursor: pointer;'>尾页</a>";
                sttable2 += "</td></tr>";
                $("#sertfoot").html(sttable2);
            } else {
                alert("没有数据！");
            }
        }, "json");
        jj();
    };

//下一页点击事件
    function downye() {
        var name = $("#name").val();
        var type = $(".myrdo:checked").val();
        var typename="";
        var url = "/official/productListajax?pageNo=" + (pageNo + 1) + "&name=" + name + "&typeWebsite=" + type;
        $.post(url, function (result) {

            if (result.officialWebsitesList.length != 0) {
                var sttable = "";
                for (var i = 0; i < result.officialWebsitesList.length; i++) {
                    if (result.officialWebsitesList[i].type==1){
                        typename="综合资讯";
                    } else if(result.officialWebsitesList[i].type==2){
                        typename="塑胶官网";
                    } else if(result.officialWebsitesList[i].type==3){
                        typename="名站";
                    } else if(result.officialWebsitesList[i].type==4){
                        typename="推荐供应商";
                    }
                    sttable += "<tr>";
                    sttable += "<td width='25px'>";
                    sttable += "<label><input type=\"checkbox\" class=\"ace\" ><span class=\"lbl\"></span></label>";
                    sttable += "</td>";
                    sttable += "<td width='80px'>";
                    sttable += result.officialWebsitesList[i].id;
                    sttable += "</td>";
                    sttable += "<td width='200px'><img src='";
                    sttable += result.officialWebsitesList[i].images;
                    sttable += "'/></td>";
                    sttable += "<td width='100px'>";
                    sttable += result.officialWebsitesList[i].name;
                    sttable += "</td>";
                    sttable += "<td width='150px'><a target=\"_blank\" href='";
                    sttable += result.officialWebsitesList[i].href;
                    sttable += "'>"+result.officialWebsitesList[i].href+"</a></td>";
                    sttable += "<td width='100px'>";
                    sttable += typename;
                    sttable += "</td>";
                    sttable += "<td width='100px'>";
                    sttable += result.officialWebsitesList[i].idValue;
                    sttable += "</td>";
                    sttable += "<td width='100px'>";
                    sttable += result.officialWebsitesList[i].idValue2;
                    sttable += "</td>";
                    sttable += "<td width='100px'>";
                    sttable += result.officialWebsitesList[i].idValue3;
                    sttable += "</td>";
                    sttable += "<td class=\"td-manage\">";
                    sttable += "<a title=\"编辑\" onclick=\"member_edit('编辑','member-add.html','4','','510')\" href=\"javascript:;\"  class=\"btn btn-xs btn-info\" ><i class=\"icon-edit bigger-120\"></i></a>";
                    sttable += "<a title=\"删除\" href=\"javascript:;\"  onclick=\"member_del(this,'1')\" class=\"btn btn-xs btn-warning\" ><i class=\"icon-trash  bigger-120\"></i></a>";
                    sttable += "</td>";
                    sttable += "</tr>";
                }
                $("#sertbody").html(sttable);
                var sttable2 = "";
                sttable2 += "<tr><td colspan='10' class='text-center'>";
                sttable2 += " <a id='suoye' href='javascript:void(0);' onclick='suoye();' style='cursor: pointer;'>首页</a>";
                sttable2 += " <a id='upye' href='javascript:void(0);' onclick='upye();' style='cursor: pointer;'>上一页</a>";
                pageNo = result.pageNo;
                pageTotal = result.pageTotal;
                if (pageNo != pageTotal) {
                    sttable2 += " <a id='downye' href='javascript:void(0);' onclick='downye();' name='down' value='下一页' style='cursor: pointer;'>下一页</a>";
                    sttable2 += " <a id='meiye' href='javascript:void(0);' onclick='meiye();' style='cursor: pointer;'>尾页</a>";
                }
                sttable2 += "</td></tr>";
                $("#sertfoot").html(sttable2);
            } else {
                alert("没有数据！");
            }
        }, "json");
        jj();
    }

//尾页点击事件
    function meiye() {
        var name = $("#name").val();
        var type = $(".myrdo:checked").val();
        var typename="";
        var url = "/official/productListajax?pageNo=" + pageTotal + "&name=" + name + "&typeWebsite=" + type;
        $.post(url, function (result1) {
            pageTotal = result1.pageTotal;
            url = "/official/productListajax?pageNo=" + pageTotal + "&name=" + name + "&typeWebsite=" + type;
            $.post(url, function (result) {

                if (result.officialWebsitesList.length != 0) {
                    var sttable = "";
                    for (var i = 0; i < result.officialWebsitesList.length; i++) {
                        if (result.officialWebsitesList[i].type==1){
                            typename="综合资讯";
                        } else if(result.officialWebsitesList[i].type==2){
                            typename="塑胶官网";
                        } else if(result.officialWebsitesList[i].type==3){
                            typename="名站";
                        } else if(result.officialWebsitesList[i].type==4){
                            typename="推荐供应商";
                        }
                        sttable += "<tr>";
                        sttable += "<td width='25px'>";
                        sttable += "<label><input type=\"checkbox\" class=\"ace\" ><span class=\"lbl\"></span></label>";
                        sttable += "</td>";
                        sttable += "<td width='80px'>";
                        sttable += result.officialWebsitesList[i].id;
                        sttable += "</td>";
                        sttable += "<td width='200px'><img src='";
                        sttable += result.officialWebsitesList[i].images;
                        sttable += "'/></td>";
                        sttable += "<td width='100px'>";
                        sttable += result.officialWebsitesList[i].name;
                        sttable += "</td>";
                        sttable += "<td width='150px'><a target=\"_blank\" href='";
                        sttable += result.officialWebsitesList[i].href;
                        sttable += "'>"+result.officialWebsitesList[i].href+"</a></td>";
                        sttable += "<td width='100px'>";
                        sttable += typename;
                        sttable += "</td>";
                        sttable += "<td width='100px'>";
                        sttable += result.officialWebsitesList[i].idValue;
                        sttable += "</td>";
                        sttable += "<td width='100px'>";
                        sttable += result.officialWebsitesList[i].idValue2;
                        sttable += "</td>";
                        sttable += "<td width='100px'>";
                        sttable += result.officialWebsitesList[i].idValue3;
                        sttable += "</td>";
                        sttable += "<td class=\"td-manage\">";
                        sttable += "<a title=\"编辑\" onclick=\"member_edit('编辑','member-add.html','4','','510')\" href=\"javascript:;\"  class=\"btn btn-xs btn-info\" ><i class=\"icon-edit bigger-120\"></i></a>";
                        sttable += "<a title=\"删除\" href=\"javascript:;\"  onclick=\"member_del(this,'1')\" class=\"btn btn-xs btn-warning\" ><i class=\"icon-trash  bigger-120\"></i></a>";
                        sttable += "</td>";
                        sttable += "</tr>";
                    }
                    $("#sertbody").html(sttable);
                    pageNo = result.pageNo;
                    pageTotal = result.pageTotal;
                    var sttable2 = "";
                    sttable2 += "<tr><td colspan='10' class='text-center'>";
                    sttable2 += " <a id='suoye' href='javascript:void(0);' onclick='suoye();' style='cursor: pointer;'>首页</a>";
                    sttable2 += " <a id='upye' href='javascript:void(0);' onclick='upye();' style='cursor: pointer;'>上一页</a>";
                    sttable2 += "</td></tr>";
                    $("#sertfoot").html(sttable2);
                } else {
                    alert("没有数据！");
                }
            }, "json");
        }, "json");
        jj();
    };


